package WizardInstall;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.cloudgarden.resource.SWTResourceManager;

class ChooseDirectoryPage extends WizardPage {
	public static final String PAGE_NAME = "Choose Directory";

	private Text text=null;
	private Text textError;
	private Button buttonOpen;
	public ChooseDirectoryPage() {
		super(PAGE_NAME, "Choose Directory Page", null);
	}

	public void createControl(Composite parent) {
		Composite topLevel = new Composite(parent, SWT.NONE);
		topLevel.setLayout(new GridLayout(2, false));
		final Shell shell=parent.getShell();
		
		
		Label l = new Label(topLevel, SWT.CENTER);
		l.setText("Enter the directory to use:");
		
		text = new Text(topLevel, SWT.SINGLE);
		text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		buttonOpen = new Button(topLevel, SWT.PUSH | SWT.CENTER);
		buttonOpen.setText("Choose Folder");
		buttonOpen.setBounds(12, 6, 92, 30);
		buttonOpen.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		buttonOpen.addSelectionListener(new SelectionListener() 
		{	
			@Override
			public void widgetSelected(SelectionEvent arg0)
			{
				DirectoryDialog dd=new DirectoryDialog(shell, SWT.OPEN);
				dd.setText("Open");
				String selected=dd.open();
				if(selected!=null)
				{
					text.setText(selected);
				}
				
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) 
			{
				// TODO Auto-generated method stub
				
			}
		});
		
		textError = new Text(topLevel, SWT.SINGLE);
		textError.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		textError.setEnabled(false);
		
		setControl(topLevel);
		setPageComplete(true);
	}
	
	public void updateTextError(String strError)
	{
		textError.setText(strError);
	}
	public String getDirectory() {
		return text.getText();
	}

	
}

